<!DOCTYPE html>
<html>

<head>
  <title>图纸名称</title>
  <meta charset="UTF-8" />
  <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
  <style>
    html,
    body {
      padding: 0px;
      margin: 0px;
    }
  </style>
    <script src='../libs/jquery-3.4.1.min.js'></script>

    <script src='../libs/core/IZrowIfUVaXF.js'></script>
    <script src='../libs/core/VT3MIEkV8AKv.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/core/buckle.js'></script>
    <script src='../libs/plugin/ht-edgetype.js'></script>
    <script src="../libs/plugin/ht-obj.js"></script>
    <script src='../libs/core/ht-ui.js'></script>
    <script src='../libs/plugin/ht-form.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
     <script src="../libs/axios.min.js"></script>

    <script src="../libs/plugin/common.js"></script>
	<script src="../libs/echarts.js"></script>
	<script src="../configs/urlConfig.js"></script>

  <script src="../libs/axios.min.js"></script>

   <script>
    function init() {
      dataModel = new ht.DataModel();

      graphView = new ht.graph.GraphView(dataModel);
      graphView.addToDOM();

      // 选中边框为0
      graphView.getSelectWidth = function () {
        return 0;
      };
      // 禁止图元移动
      graphView.setMovableFunc(function () {
        return false;
      });
     // var attributeConfig = {
      //  url: "http://172.16.11.150/"
      //};

      graphView.deserialize("displays/冀北/消纳/布局.json", function (
        json,
        dm,
        g2d,
        datas
      ) {
        //ht.Default.xhrLoad('displays/冀北/消纳/增发电量.json', function (text) {

        // var json = ht.Default.parse(text);
        // if (json.title) document.title = json.title;
        // console.log("加载图纸");
        console.log(dm);
        //自适应屏幕
        graphView.fitContent(true);
        treeTableView = new ht.widget.TreeTableView(dataModel);
        //获取按钮日期
        var y_button = dataModel.getDataByTag("y_button");
        //y_button.a("ht.background", "rgb(45,202,171)");

        var m_button = dataModel.getDataByTag("m_button");
        m_button.a("ht.background", "rgb(45,202,171)");

        //日按钮获取
        var day_button = dataModel.getDataByTag("day_button");



        const startTime = dataModel.getDataByTag("startTime");
        const endTime = dataModel.getDataByTag("endTime");
        endTime.a("ht.value", getNowDay(new Date()));
        startTime.a("ht.value", getFirstDayOfMonth(new Date()));
        var time1 = startTime.a("ht.value");
        var time2 = endTime.a("ht.value");
        var date1 = new Date(time1);
        var date2 = new Date(time2);

        //获取本年的最后一天
        //获取区域
        // const areas = dataModel.getDataByTag("areas");


        var temp1 = "";
        var temp2 = "";


        var cesValue = [];

        //获取折线图
        const t_substation = dataModel.getDataByTag("t_substation");

        values = updateDataModel(
          "/epplatform/v1/increasedElectricity",

          date1.getTime(),
          date2.getTime()
        );
        getlistAdditionalPowerGeneration(

          date1.getTime(),
          date2.getTime()

        );
        //初始化数据年月日按钮联动

        var colors = ["rgb(45,202,171)", "rgb(255,255,255)", "#ccc"];

        //日按钮事件
        day_button.s("onClick", () => {
          getCheck("day_button", "m_button", "y_button");
          getTagNameOnChange("day", null);
        });
        //通用改变颜色
        function getCheck(name1, name2, name3) {
          if (name1 == "day_button") {
            day_button.a("ht.background", colors[0]);
            day_button.a("ht.borderColor", colors[0]);
          } else if (name1 == "m_button") {
            m_button.a("ht.background", colors[0]);
            m_button.a("ht.borderColor", colors[0]);
          } else if (name1 == "y_button") {
            y_button.a("ht.background", colors[0]);
            y_button.a("ht.borderColor", colors[0]);
          }

          var button_temp01 = dataModel.getDataByTag(name2);
          var button_temp02 = dataModel.getDataByTag(name3);
          var button_bc01 = button_temp01.a("ht.background");
          var button_bc02 = button_temp02.a("ht.background");

          if (button_bc01 == colors[0] || button_bc02 == colors[0]) {
            button_temp01.a("ht.background", colors[1]);
            button_temp01.a("ht.borderColor", colors[2]);
            button_temp02.a("ht.background", colors[1]);
            button_temp02.a("ht.borderColor", colors[2]);
          }
        }

        //月按钮
        m_button.s("onClick", () => {
          getCheck("m_button", "day_button", "y_button");

          getTagNameOnChange("month", null);
        });
        //年按钮事件
        y_button.s("onClick", () => {
          getCheck("y_button", "m_button", "day_button");
          getTagNameOnChange("year", null);
        });

        //日期框改变事件
        startTime.a("ht.onChange", (oldVal, newVal, data, view) => {
          getTagNameOnChange("startTime", newVal);
        });

        //日期框改变事件
        endTime.a("ht.onChange", (oldVal, newVal, data, view) => {
          getTagNameOnChange("endTime", newVal);
        });


        //传递不同的name触发接口实现联动
        function getTagNameOnChange(name, val) {
          //debugger;
          //日期框改变事件

          switch (name) {
            case "startTime": //开始日期
              time1 = val;
              date1 = new Date(time1);
              //获取地图数据
              values = updateDataModel(
                "/epplatform/v1/increasedElectricity",

                date1.getTime(),
                date2.getTime()
              );
              getlistAdditionalPowerGeneration(

                date1.getTime(),
                date2.getTime()
              );

              break;
            case "endTime": //结束日期
              time2 = val;
              date2 = new Date(time2);
              //获取地图数据
              values = updateDataModel(
                "/epplatform/v1/increasedElectricity",

                date1.getTime(),
                date2.getTime()
              );
              getlistAdditionalPowerGeneration(

                date1.getTime(),
                date2.getTime()
              );

              break;


            case "year": //年按钮
              //获取当前前一天时间
              //获取当前年第一天
              time2 = getNowDay(new Date());
              time1 = getFirstDayOfYear(new Date());
              startTime.a("ht.value", time1);
              endTime.a("ht.value", time2);
              date1 = new Date(time1);
              date2 = new Date(time2);
              //获取地图数据
              values = updateDataModel(
                "/epplatform/v1/increasedElectricity",
                date1.getTime(),
                date2.getTime()
              );
              getlistAdditionalPowerGeneration(

                date1.getTime(),
                date2.getTime()
              );

              break;
            case "month": //月按钮
              time1 = getFirstDayOfMonth(new Date());
              time2 = getNowDay(new Date());
              endTime.a("ht.value", time2);
              startTime.a("ht.value", time1);
              date1 = new Date(time1);
              date2 = new Date(time2);
              //获取地图数据
              values = updateDataModel(
                "/epplatform/v1/increasedElectricity",

                date1.getTime(),
                date2.getTime()
              );
              getlistAdditionalPowerGeneration(
                date1.getTime(),
                date2.getTime()

              );

              break;
            case "day": //日按钮

              time1 = getNowDay(new Date()) + " 00:00:00";
              time2 = getNowDay(new Date()) + " 23:59:59";
              endTime.a("ht.value", time2);
              startTime.a("ht.value", time1);
              date1 = new Date(time1);
              date2 = new Date(time2);
              //获取地图数据
              values = updateDataModel(
                "/epplatform/v1/increasedElectricity",

                date1.getTime(),
                date2.getTime()
              );
              getlistAdditionalPowerGeneration(
                date1.getTime(),
                date2.getTime()

              );

              break;
            default:
              //默认代码块
          }
        }





        var arr1 = []; //利用小时数据
        var arr2 = []; //增发概率
        var arr3 = [];
        //折线图接口数据
        function getlistAdditionalPowerGeneration(

          startTime,
          endTime

        ) {
          $.ajax({
            type: "GET",
            async: true, //同步请求

            url: attributeConfig.url +
              "/epplatform/v1/additionalProbabilitiesAndUseOfHours?&startTime=" +
              startTime +
              "&endTime=" +
              endTime,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
              console.log("远程数据请求data", data);

              if (data.code == 0) {
                t_substation.a("data1", data.data.additionalProbabilities);
                t_substation.a("data2", data.data.useOfHours);
                t_substation.a("names", data.data.stationName);
              }
            },
            error: function () {
              console.log("失败，请稍后再试！");
            }
          });
        }

        //地图图标实现方法如下
        function updateDataModel(geturl, startTime, endTime) {
          $.ajax({
            type: "GET",
            async: false, //同步请求
            // startTime : System.currentTimeMillis() ,
            // endTime : System.currentTimeMillis(),
            url: attributeConfig.url +
              geturl +
              "?&startTime=" +
              startTime +
              "&endTime=" +
              endTime,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
              if (data.code == 0) {
                values = data.data;
                console.log(values)
                createNodes(values);
              }
            },
            error: function () {
              alert("失败，请稍后再试！");
            }
          });
          return values;
        }
        //创建node
        function createNodes(data) {
          //获取数组中的最大值
          getElement();
          var max = getMaxNum(data);

          for (var i = 0; i < data.length; i++) {
            // node.setLayer("2"); 
            var temp = data[i];
            var node = dataModel.getDataByTag(temp.area); //发光环柱子 
            var zhuzi_heigth = 0;
            if (max != 0) {
              zhuzi_heigth = temp.increasedElectricity / max
            }

            // node.setName(temp.area); //设置高度缩放 //
            //node.setTag(temp.area);
            node.a("value", temp.increasedElectricity);
            node.a("caijie", zhuzi_heigth);
            //node.setDisplayName(temp // .area); // // node.setId(temp.area); 
            node.s("2d.visible", true); //可见
            node.s("interactive", true);
          }
        }
        //改变节点通用方法
        function getElement(name) {
          var names = ["秦皇岛", "张家口", "廊坊", "唐山", "承德"];
          names.forEach(element => {
            var tag = dataModel.getDataByTag(element);

            if (element != name) {
              if (name == "冀北") {
                if (tag != undefined) tag.s("2d.visible", true);
              } else {
                if (tag != undefined) tag.s("2d.visible", false);
              }
            } else {
              if (tag != undefined) tag.s("2d.visible", true);
            }
          });
        }

        //循环取出最大值
        function getMaxNum(datas) {
          // console.log(datas);
          //获取

          //创建数组并赋值
          var strNum = [];
          for (var i = 0; i < datas
            .length; i++) { // 
            //  console.log(datas[i]);
            strNum.push(datas[i].increasedElectricity);
          } //通过获取数组变量和原来的数组做对比 
          var max = strNum[0]; //对比结果是最大值 
          var min = strNum[0]; //对比结果是最小值 //通过for循环获取对比次数
          for (var i = 0; i <
            strNum.length; i++) { // 最大值 
            if (max < strNum[i]) { //通过if判断把最大值赋给max；
              max = strNum[i];
            } // //最小值 
            if (min > strNum[i]) {
              //通过if判断把最小值赋给min；
              min = strNum[i];
            }
            //console.log("最大值是" + max);
            // console.log("最小值是" + min);
          }

          return max;
        }

      });
    }
  </script>
</head>

<body onload="init()"></body>

</html>